package com.nf.service;

import com.nf.entity.Condition;
import com.nf.entity.Students;
import com.nf.entity.house;
import com.nf.mappers.StudentMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

public class StudentServicelmpl implements  StudentService{
    private StudentMapper studentMapper=null;

    public Students test() {
        //还没有神，于是写以下几行代码
        SqlSession session = null;
        try {
            //高度的耦合（后面要想办法彻底的解构）
            InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
            SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            session = sessionFactory.openSession();
            //直接创建一个dao层的实现类
            studentMapper = session.getMapper(StudentMapper.class);
            System.out.println("我真的很想知道这个实现类是谁："+studentMapper);

        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }

        List<house> findhouse = studentMapper.findhouse();
        System.out.println(findhouse.size());
        for (house h:findhouse){
            System.out.print(h.getName());
            for (Students s:h.getStudentsList()){
                System.out.print("    "+s.getName());
            }
            System.out.println();
        }



//        Map<String,Object> student = studentMapper.findStudentById(2);
//        System.out.println(  student.get("dob") ) ;


//        List<Condition> conditionList=studentMapper.getCondition();
//        for(Condition c:conditionList){
//            System.out.println(c.getName());
//        }
           return null;
    }
}
